//
//  TMDetailsVc.m
//  MoviesInfo
//
//  Created by zhangkai on 2023/4/30.
//  Copyright © 2023 Tobias Ruano. All rights reserved.
//

#import "TMDetailsVc.h"
#import "TMTVInfoVC.h"
#import "TMMovieInfoVC.h"
@interface TMDetailsVc ()
@property(nonatomic)UIImageView *headIcon;
@property(nonatomic)UILabel *movieTitle;
@property(nonatomic)UILabel *detailsInfoLabel;
@property(nonatomic,strong)NSMutableArray *arr;
@property(nonatomic,strong)UIScrollView *mainScro;

@end

@implementation TMDetailsVc
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:YES];
}

-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [self.navigationController setNavigationBarHidden:NO];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    self.arr = @[].mutableCopy;
    self.view.backgroundColor = [UIColor whiteColor];
    

    
    
    
    
    
    TMNavView *nav = [TMNavView new];
    nav.backgroundColor = [UIColor blueColor];
    [self.view addSubview:nav];
    
    self.mainScro = [[UIScrollView alloc] init];
    [self.view addSubview:self.mainScro];
    [self.mainScro mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view);
        make.right.equalTo(self.view);
        make.top.equalTo(nav.mas_bottom);
        make.bottom.equalTo(self.view);
    }];
    
    
    self.headIcon = [UIImageView new];
    self.headIcon.backgroundColor = [UIColor yellowColor];
    self.headIcon.contentMode = UIViewContentModeScaleAspectFill;
    [self.mainScro addSubview:self.headIcon];
    [self.headIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mainScro);
        make.left.equalTo(self.mainScro);
        make.width.mas_equalTo(kScreenW);
//        make.right.equalTo(self.view);
        make.height.mas_equalTo(500);
    }];
    self.headIcon.clipsToBounds = YES;
    
    self.movieTitle = [UILabel new];
    self.movieTitle.text = @"title";
    self.movieTitle.font = [UIFont systemFontOfSize:28 weight:UIFontWeightBold];
    self.movieTitle.textColor = [UIColor blackColor];
    [self.mainScro addSubview:self.movieTitle];
    [self.movieTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.mainScro);
        make.top.equalTo(self.headIcon.mas_bottom).offset(25);
    }];
    
//    t'a'g
    
    UILabel *tagLabel = [UILabel new];
    tagLabel.textColor = [UIColor blueColor];
    tagLabel.font = [UIFont systemFontOfSize:20];
    tagLabel.text = @"Tag";
    [self.mainScro addSubview:tagLabel];
    [tagLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mainScro).offset(25);
        make.top.equalTo(self.movieTitle.mas_bottom).offset(25);
    }];
    
    
    
    UIButton *curBtn = [UIButton new];
    for (int i = 0; i<4; i++) {
        UIButton *btn = [UIButton new];
        btn.userInteractionEnabled = NO;
        btn.contentEdgeInsets = UIEdgeInsetsMake(0, 8, 0, 8);
        [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        btn.titleLabel.font = [UIFont systemFontOfSize:14];
        btn.backgroundColor = [UIColor linkColor];
        [self.mainScro addSubview:btn];
        [btn mas_makeConstraints:^(MASConstraintMaker *make) {
            if(i == 0){
                make.left.equalTo(self.mainScro).offset(25);
            }else{
                make.left.equalTo(curBtn.mas_right).offset(20);
            }
            make.top.equalTo(tagLabel.mas_bottom).offset(10);
        }];
        
        curBtn = btn;
        btn.hidden = YES;
        [self.arr addObject:btn];
    }
    
    UILabel *introduce = [UILabel new];
    introduce.textColor = [UIColor blueColor];
    introduce.font = [UIFont systemFontOfSize:20];
    introduce.text = @"Actor List";
    [self.mainScro addSubview:introduce];
    [introduce mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mainScro).offset(25);
        make.top.equalTo(curBtn.mas_bottom).offset(15);
    }];
    

    self.detailsInfoLabel = [UILabel new];
    self.detailsInfoLabel.textColor = [UIColor blackColor];
    self.detailsInfoLabel.font = [UIFont systemFontOfSize:14];
    self.detailsInfoLabel.numberOfLines = 0;
    self.detailsInfoLabel.text = @"info";
    [self.mainScro addSubview:self.detailsInfoLabel];
    [self.detailsInfoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mainScro).offset(25);
        make.width.mas_equalTo(kScreenW-50);
//        make.right.equalTo(self.view).offset(-25);
        make.top.equalTo(introduce.mas_bottom).offset(10);
    }];
    
    
    UIButton *pushbtn = [UIButton new];
    pushbtn.backgroundColor = [UIColor blueColor];
    pushbtn.contentEdgeInsets = UIEdgeInsetsMake(0, 8, 0, 8);
    [pushbtn setTitle:@"观看" forState:UIControlStateNormal];
    [pushbtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    pushbtn.titleLabel.font = [UIFont systemFontOfSize:18];
    [self.view addSubview:pushbtn];
    [pushbtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view);
        make.width.mas_equalTo(300);
        make.height.mas_equalTo(44);
        make.bottom.equalTo(self.view).offset(-kTabBarBottomSecurityH-20);
    }];
    [pushbtn addTarget:self action:@selector(clickPush) forControlEvents:UIControlEventTouchUpInside];
    
    
    
    [self configDic:self.dic];
    
//    introduce
}

- (void)clickPush{
    

    NSString *type = [self.dic objectForKey:@"165"];
    if(![type isEqualToString:@"tt_mflx"]){
        TMMovieInfoVC *VC = [TMMovieInfoVC new];
        VC.idstr = [self.dic objectForKey:@"id"];
        [self.navigationController pushViewController:VC animated:YES];
    }else{
        TMTVInfoVC *VC = [TMTVInfoVC new];
        VC.idstr = [self.dic objectForKey:@"id"];
        [self.navigationController pushViewController:VC animated:YES];
    }
//
    
    
}

-(void)configDic:(NSDictionary *)dic{

    
    [self.headIcon sd_setImageWithURL:[NSURL URLWithString:[dic objectForKey:@"cover"]]];
    self.movieTitle.text = [dic objectForKey:@"title"];
    self.detailsInfoLabel.text = [dic objectForKey:@"stars"];

    NSString *str = [dic objectForKey:@"356"];
    NSArray *arr =  [str componentsSeparatedByString:@","];
    for (int i = 0; i<arr.count; i++) {
        if(i > 3){
            
        }else{
            UIButton *btn = self.arr[i];
            btn.hidden = NO;
            [btn setTitle:arr[i] forState:UIControlStateNormal];
        }
    }
    
    
    
    
    [self.view layoutIfNeeded];
//    [self.view setNeedsLayout];
 
    
    NSLog(@"%f",self.detailsInfoLabel.frame.origin.y+self.detailsInfoLabel.frame.size.height);
    
    self.mainScro.contentSize = CGSizeMake(0, self.detailsInfoLabel.frame.origin.y+self.detailsInfoLabel.frame.size.height+kTabBarBottomSecurityH+80);
    
    
    
}

@end
